{% macro render_nav_bar(user, nav_bar, titlename, g) %}
  <nav class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation">
    {% if g.request_from_mobile %}
      <div class="navbar-header">
        <a class="navbar-brand">
          LITE-MMS
          <small><i>- {{ titlename }}</i></small>
        </a>
        {% if user.is_authenticated and nav_bar is defined %}
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        {% endif %}
      </div>
      {% if user.is_authenticated and nav_bar %}
        <nav class="collapse navbar-collapse navbar-ex1-collapse">
          {{ nav_bar.as_ul("active")|safe }}
          <ul class="nav navbar-nav">
            <li>
              <a href="{{ url_for('auth.logout') }}">
                <i class="fa fa-power-off fa-lg text-danger"></i>
              </a>
            </li>
          </ul>
        </nav>
      {% endif %}
    {% else %}
      <div class="navbar-header">
        <a class="navbar-brand" href="#">
          LITE-MMS
        </a>
        {% if user.is_authenticated and nav_bar is defined %}
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        {% endif %}
      </div>
      {% if user.is_authenticated and nav_bar is defined %}
        <nav class="collapse navbar-collapse navbar-ex1-collapse">
          {{ nav_bar.as_ul("active", grouped=True)|safe }}
          <form class="navbar-form navbar-right" role="search" action="{{ url_for('search.search') }}" method="GET">
            <div class="form-group">
              <input class="form-control" type="text" placeholder="关键词..." name="content"
                     {% if keywords %}value="{{ keywords }}"{% endif %}/>
            </div>
            <button class="btn btn-default"><i class="fa fa-search"></i></button>
          </form>

          <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" href="#">
                <strong><i class="fa fa-user fa-fw"></i>{{ user.group_name }}&nbsp;{{ user.username }}
                </strong>
                <span class="fa fa-caret-down"></span>
              </a>
              <ul class="dropdown-menu" role="menu">
                {% if user.groups|length > 1 %}
                  <li class="text-center">
                    <a href="#switch-group-modal" data-role="switch-group" data-toggle="modal">
                      <i class="fa fa-cogs fa-fw"></i>&nbsp;{{ user.group_name }}
                    </a>
                  </li>
                  <li class="divider"></li>
                {% endif %}
                <li class="text-center">
                  <a href="{{ url_for('auth.logout') }}"><i class="fa fa-sign-out"></i>&nbsp;退出</a>
                </li>
              </ul>
            </li>
        </nav>
        </div>
      {% endif %}
    {% endif %}
  </nav>
{% endmacro %}
